
@array_tped_snps = ();
$file="chr22_out_ori.tped";
chomp($file);
open(BUFF,$file) or die " no file $file found\n";
open(BUFF1,"impute_dosage.txt") or die "no file found impute_dosage.txt\n";
while($tline=<BUFF>)
{
	$line=<BUFF1>;
	chomp($line);
	@a = split(" ",$line);
	$num_tped =0;
	undef(@array_tped_snps);
	undef(@mainar);
	chomp($tline);
	@tp_array=split(" ",$tline);
	$tped_snp1=$a[1];
	$tped_snp2=$a[2];
	$mainar[0] = $tp_array[1];
	$mainar[1] = $tped_snp1;
	$mainar[2] = $tped_snp2;
	$A=3;
	for($g=4;$g<@tp_array;$g++)
	{
		$ssnp1 = $tp_array[$g];
		$g++;
		$ssnp2 = $tp_array[$g];	
		if($ssnp1 eq $tped_snp1 && $ssnp2  eq $tped_snp1) 
		{
			$mainar[$A] = "0";
			$A++;
		}
		elsif($ssnp1 eq $tped_snp2 && $ssnp2  eq $tped_snp2)
        	{
                	$mainar[$A] = "2";	
			$A++;
        	}
		elsif($ssnp1 eq "0" && $ssnp2  eq "0")
        	{
                	$mainar[$A] = "NA";
			$A++;
        	}
		else
		{		
			$mainar[$A] = "1";
			$A++;
		}
	}	
	$line = join(" ",@mainar);
	print $line."\n";
}
